package com.example.bootdemo.redis.controller;

import com.example.bootdemo.redis.model.TaskSynData;
import com.example.bootdemo.redis.redis.RedisManager;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/redis")
public class RedisController {
    @Resource
    private RedisManager redisManager;

    @RequestMapping(value = "/redis/send", method = RequestMethod.GET)
    public String redisSend() {
        TaskSynData taskSynData = new TaskSynData();
        taskSynData.setType("type");
        taskSynData.setName("测试");
        redisManager.set("test", "测试");
        return "发送成功";
    }
    @RequestMapping(value = "/redis/order", method = RequestMethod.GET)
    public void createOrder(@RequestParam String id) {


        // 在Redis中存储一个键，设置30分钟过期orderId
        redisManager.set("order:" + id, id, 30);
    }

    @RequestMapping(value = "/redis/order1", method = RequestMethod.GET)
    public void createOrder1(@RequestParam String id) {


        // 在Redis中存储一个键，设置30分钟过期orderId
        redisManager.set("order1:" + id, id, 30);
    }

    // 当键过期时，Redis会自动调用该方法（需要配置Redis的过期事件通知功能）

}
